package com.example.zhongshuishi.utils;


import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.nio.charset.StandardCharsets;

public class KSXJWTUtil {
    private static final int appId = 618654;  // 替换为实际AppId
    private static final String appKey = "d2b4173921cc486892362f9080d9ec60"; // 替换为实际AppKey

    // 生成JWT令牌（actionId=201表示登录）
    public static String getJWTInfo(String actionId) {
        try {
            return Jwts.builder()
                    .claim("exp", System.currentTimeMillis() + 1000 * 30) // 过期时间30秒
                    .claim("action_id", actionId)
                    .signWith(SignatureAlgorithm.HS256, appKey.getBytes(StandardCharsets.UTF_8))
                    .compact();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
    // 获取接口URL
    public static String getPostUrl(String actionId) {
        String domainUrl = "https://api.kaoshixing.com";
        return String.format("%s/api/company/data/%d/?jwt=%s",
                domainUrl, appId, getJWTInfo(actionId));
    }
}